package com.kusiri.kframework.component.property.component
{
	import com.kusiri.kframework.component.property.IKfComponentPropertyEditor;
	import com.kusiri.kframework.metadata.KfComponentConfiguration;
	
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.controls.ComboBox;

	public class KfComponentComponentPropertyEditor extends ComboBox implements IKfComponentPropertyEditor
	{
		/**
		 * The available components
		 */
		public var components : Array;
		
		/**
		 * 
		 */
		public function set configuration (xml:XML) : void
		{
			var arrayCollection : ArrayCollection = new ArrayCollection(components);
			var sort:Sort = new Sort();
     		sort.fields = [new SortField("name",true)];
			arrayCollection.sort = sort;
			arrayCollection.refresh();
			
			dataProvider = arrayCollection;
			
			for each ( var object : KfComponentConfiguration in components )
			{
				if (object.id == xml.toString())
				{
					selectedItem = object;
					break;
				}
			}
			
			labelField = 'name';
		}
		
		/**
		 * 
		 */
		public function get configuration () : XML
		{
			var xml : XML = new XML(selectedItem.id);
			return xml;
		}
		
		/**
		 * Array of IKfComponentPropertyValidationError
		 */
		public function get validationErrors () : Array
		{
			return [];
		}
		
	}
}